package com.nf.health.app.adapter;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hyphenate.easeui.widget.CircularImage;
import com.nf.health.app.R;
import com.nf.health.app.inquiry.docdetail.DocDetailActivity;
import com.nf.health.app.models.HealthStateInfo;
import com.nf.health.app.utils.ActivityUtils;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Jason on 2016/3/31.
 */
public class ItemHealthyDoctorAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    List<HealthStateInfo.DocotrListEntity> list;

    Activity act;
    public ItemHealthyDoctorAdapter(List<HealthStateInfo.DocotrListEntity> list, Activity act) {
        this.list = list;
        this.act = act;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_healthy_doc, parent, false);
        return new ItemSchemeViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ItemSchemeViewHolder itemHolder = (ItemSchemeViewHolder) holder;
        itemHolder.id_index_gallery_item_text.setText(list.get(position).getNick());//list.get(position).getName()
        //itemHolder.id_index_gallery_item_image.setText(list.get(position).getDetail());
        ImageLoaderUtils.getinstance(act).getImage(itemHolder.iv_index_gallery_item_image,list.get(position).getHimg(),R.drawable.default_head);
        itemHolder.id_index_doc_gray.setText(list.get(position).getProfessional());
        itemHolder.rl_item_doc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString(DocDetailActivity.DOCTORID, list.get(position).getDoctorid());
                ActivityUtils.showActivity(act, DocDetailActivity.class, bundle);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class ItemSchemeViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv_index_gallery_item_image)
        CircularImage iv_index_gallery_item_image;
        @Bind(R.id.id_index_gallery_item_text)
        TextView id_index_gallery_item_text;
        @Bind(R.id.rl_item_doc)
        RelativeLayout rl_item_doc;
        @Bind(R.id.id_index_doc_gray)
        TextView id_index_doc_gray;

        public ItemSchemeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
